package com.nkzy.mapper;

import com.nkzy.pojo.Address;
import org.apache.ibatis.annotations.*;

import java.util.List;

@Mapper
public interface AddressMapper1 {

    @Insert("INSERT INTO address(id, user_id, address_detail, create_time, update_time) " +
            "VALUES(#{id}, #{userId}, #{addressDetail}, #{createTime}, #{updateTime})")
    int insertAddress(Address address);

    @Delete("DELETE FROM address WHERE id = #{id}")
    int deleteAddressById(Long id);

    @Update("UPDATE address SET user_id = #{userId}, address_detail = #{addressDetail}, " +
            "update_time = #{updateTime} WHERE id = #{id}")
    int updateAddress(Address address);

    @Select("SELECT * FROM address WHERE id = #{id}")
    Address selectAddressById(Long id);

    @Select("SELECT * FROM address")
    List<Address> selectAllAddresses();

    @Select("<script>" +
            "SELECT * FROM address WHERE id IN " +
            "<foreach item='id' index='index' collection='list' open='(' separator=',' close=')'>" +
            "#{id}" +
            "</foreach>" +
            "</script>")
    List<Address> selectAddressesByIds(List<Long> ids);
}